var callback = function(data) {
	// $('#tmp').html(data);
	var json = eval("(" + data + ")");
	if (json.code != 200) {
		alert("用户信息获取失败，请重新登入");
		return;
	}
	var userinfo = json.user;
	$('#t_name').html(userinfo.username);
	$('#t_status').html(
			userinfo.status == "0" ? "<font color='green'>正常</font>"
					: "<font color='red'>停用</font>");
	$('#t_create_time').html(userinfo.createTime);
	$('#t_bind_device_name').html(userinfo.bindDeviceName);
	$('#t_authority').html(json.authority);
	$('#t_mobile').html(userinfo.mobile);
	$('#t_email').html(userinfo.email);
	
	
	var server =json.serverInfo;
	$('#serverEnd').html(server.endTime);
	$('#days').html(server.days);
	var backupTimes=json.backuptimes;
	$('#todayCount').html(backupTimes.todayCount);
	$('#allCount').html(backupTimes.allCount);
	
	var space=json.statics;
	
	$('#all_space').html(space.countSize);
	$('#no_space').html(space.usageSize);
	$('#yes_space').html(space.availableSpaceSize);
	

	var totabB = json.statics.countSize;
	var availableSpaceSizeB = json.statics.availableSpaceSize;

	var total = Number((totabB).toFixed(2));
	var used = Number((total - availableSpaceSizeB).toFixed(2));

	usedChart(used,total-used);
};

function usedChart(used,rest){
	$('#chart').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'
        },
        credits:{
            text: '',
            href: ''
        },
        title: {
            text: '存储空间使用情况'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'blue'
                    }
                }
            }
        },
        series: [{
            name: "空间比率",
            colorByPoint: true,
            data: [ {
                name: "已使用",
                y: used,
                color:"red"
            }, {
                name: "剩余",
                y: rest,
                color:"green"
            }]
        }]
    });
}

$(function() {
	var service = new EbeimService();
	service.getUserInfo(callback);
});

//var arr = {};
//var days = 10;
//function lineChartProcess(obj) {
//	var today = new Date();
//	var day = today.getDate();
//	var month = today.getMonth();
//	var year = today.getFullYear();
//	for (var i = days - 1; i >= 0; i--) {
//		var nsStr = new Date(year, month, (day - i), 0, 0, 0).toLocaleString();
//		var neStr = new Date(year, month, (day - i), 23, 59, 59)
//				.toLocaleString();
//		var objStr = new Date(obj.endTime * 1).toLocaleString();
//		var ns = new Date(year, month, (day - i), 0, 0, 0).getTime();
//		var ne = new Date(year, month, (day - i), 23, 59, 59).getTime();
//		if (obj.status == 0 && obj.endTime * 1 > ns && obj.endTime * 1 < ne) {
//			arr[ns] == undefined ? arr[ns] = obj.usedSpace
//					: arr[ns] += obj.usedSpace;
//		}
//
//	}
//}

//var chartCB = function(data) {
//	var timeData = {};
//	var data = eval("(" + data + ")");
//	for (var i = 0; i < data.length; i++) {
//		var json = eval("(" + data[i] + ")");
//		var list = json.list.objList;
//		for (var j = 0; j < list.length; j++) {
//			var obj = list[j];
//			lineChartProcess(obj);
//		}
//	}
//
//	var labels = [];
//	var data = [];
//	for ( var key in arr) {
//		labels[labels.length++] = new Date(key * 1).toLocaleString().substring(
//				0, 10);
//		data[data.length++] = (arr[key] / 1024 / 1024).toFixed(2);
//	}
//	if (data.length == 0) {
//		data = [ 0, 0, 0, 0, 0 ];
//		labels = [ 0, 0, 0, 0, 0 ];
//	}
//	var data = {
//		labels : labels,
//		datasets : [ {
//			fillColor : "#BEDA86",
//			strokeColor : "#438119",
//			pointColor : "#438119",
//			pointStrokeColor : "#fff",
//			data : data
//		} ]
//	}
//	lineStorageChart(data);
//}